#!/bin/bash

# Gemini CLI - 国内大模型测试脚本

set -e

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'

print_info() {
    echo -e "${BLUE}ℹ${NC} $1"
}

print_success() {
    echo -e "${GREEN}✓${NC} $1"
}

print_warning() {
    echo -e "${YELLOW}⚠${NC} $1"
}

print_error() {
    echo -e "${RED}✗${NC} $1"
}

echo "======================================"
echo "Gemini CLI - 国内大模型配置测试"
echo "======================================"
echo ""

# 检查环境变量文件
if [ -f "$HOME/.gemini/.env" ]; then
    print_success "找到配置文件: $HOME/.gemini/.env"
    source "$HOME/.gemini/.env"
else
    print_warning "未找到配置文件: $HOME/.gemini/.env"
    print_info "请先创建配置文件，可以参考: ./env.example"
    exit 1
fi

echo ""
print_info "检查配置..."
echo ""

# 检查模型提供商
if [ -z "$LLM_PROVIDER" ]; then
    print_error "未设置 LLM_PROVIDER"
else
    print_success "模型提供商: $LLM_PROVIDER"
fi

# 检查 API Key
case "$LLM_PROVIDER" in
    deepseek)
        if [ -n "$DEEPSEEK_API_KEY" ]; then
            print_success "DeepSeek API Key: ${DEEPSEEK_API_KEY:0:10}..."
        else
            print_error "未设置 DEEPSEEK_API_KEY"
        fi
        ;;
    qwen)
        if [ -n "$QWEN_API_KEY" ]; then
            print_success "Qwen API Key: ${QWEN_API_KEY:0:10}..."
        else
            print_error "未设置 QWEN_API_KEY"
        fi
        ;;
    kimi)
        if [ -n "$KIMI_API_KEY" ]; then
            print_success "Kimi API Key: ${KIMI_API_KEY:0:10}..."
        else
            print_error "未设置 KIMI_API_KEY"
        fi
        ;;
    doubao)
        if [ -n "$DOUBAO_API_KEY" ]; then
            print_success "Doubao API Key: ${DOUBAO_API_KEY:0:10}..."
        else
            print_error "未设置 DOUBAO_API_KEY"
        fi
        ;;
    glm)
        if [ -n "$GLM_API_KEY" ]; then
            print_success "GLM API Key: ${GLM_API_KEY:0:10}..."
        else
            print_error "未设置 GLM_API_KEY"
        fi
        ;;
    *)
        print_warning "未知的提供商: $LLM_PROVIDER"
        ;;
esac

# 检查搜索引擎
echo ""
if [ -n "$SEARCH_ENGINE" ]; then
    print_success "搜索引擎: $SEARCH_ENGINE"
    
    case "$SEARCH_ENGINE" in
        bing)
            if [ -n "$BING_SEARCH_API_KEY" ]; then
                print_success "Bing API Key: ${BING_SEARCH_API_KEY:0:10}..."
            else
                print_warning "未设置 BING_SEARCH_API_KEY (搜索功能将不可用)"
            fi
            ;;
        baidu)
            if [ -n "$SERPAPI_KEY" ]; then
                print_success "SerpAPI Key: ${SERPAPI_KEY:0:10}..."
            else
                print_warning "未设置 SERPAPI_KEY (搜索功能将不可用)"
            fi
            ;;
        google)
            print_info "使用 Google 搜索 (需要 Gemini 认证)"
            ;;
    esac
else
    print_warning "未设置 SEARCH_ENGINE"
fi

echo ""
echo "======================================"
print_info "配置检查完成！"
echo ""
print_info "如果所有配置都正确，可以运行:"
echo "  ./start-chinese-llm.sh"
echo ""
print_info "或者直接运行:"
echo "  wfh-cli"
echo "  或"
echo "  gemini"
echo "======================================"

